package com.asiainfo.dacp.catalog.util;

import com.asiainfo.dacp.util.JsonHelper;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import org.springframework.stereotype.Component;




@Component
public class JsonPropertiesReader
{
  private static JsonPropertiesReader JSON_PROPERTIES_READER = new JsonPropertiesReader();
  
  public static JsonPropertiesReader getInstance() {
    return JSON_PROPERTIES_READER;
  }
  
  public Map readProperties(String path) {
    BufferedReader reader = null;
    laststr = "";
    try {
      InputStream is = getClass().getResourceAsStream(path);
      InputStreamReader inputStreamReader = new InputStreamReader(is, "UTF-8");
      reader = new BufferedReader(inputStreamReader);
      String tempString = null;
      while ((tempString = reader.readLine()) != null) {
        laststr = laststr + tempString;
      }
      reader.close();
      











      return (Map)JsonHelper.getInstance().read(laststr);
    }
    catch (IOException e)
    {
      e.printStackTrace();
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  }
}